@echo off

if "%1"=="--help" goto usageError
if "%1"=="/?" goto usageError
if "%1"=="-h" goto usageError

:begin

SET OutputDirectory=%~d0%~p0out

if NOT "%1"=="" SET OutputDirectory=%1

echo Creating output directory %OutputDirectory% ...
md %OutputDirectory% > nul 2>&1

pushd Localization
for /D %%a in (*.*) do (

  echo Processing %%a ...
  md %OutputDirectory%\%%a > nul 2>&1

  pushd %%a
  for /D %%f in (*.*) do (
    @echo   Processing %%f ...
    md %OutputDirectory%\%%a\%%f > nul 2>&1
    
    "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen.exe" %%f\strings.txt %OutputDirectory%\%%a\%%f\%%a.%%f.resources > nul
    "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\Al.exe" /embed:%OutputDirectory%\%%a\%%f\%%a.%%f.resources /c:%%f /out:%OutputDirectory%\%%a\%%f\%%a.resources.dll > nul

    if errorlevel 1 goto end
    
    del %OutputDirectory%\%%a\%%f\%%a.%%f.resources
  )
  popd
)
popd
echo Done

goto end
:usageError
echo USAGE:
echo   %0 [OutputDirectory]
goto end
:end